#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

void solve()
{
    ll n;
    cin >> n;
    vector<ll> w(n + 1);
    vector<vector<ll>> pos(n + 1);

    for (ll i = 1; i <= n; i++) {
        ll x;cin >> x;
        pos[x].push_back(i);
    }
    for (ll i = 1; i <= n; i++) cin >> w[i];

    for (ll i = 1;i <= n;i++) {
        auto& g = pos[i];
        if (g.size() == n) {
            cout << 0 << ' ';
        } else {
            ll cnt = 1, len = 0;
            g.push_back(-10);
            for (ll l = 0, r = 0;r + 1 < g.size();r++) {
                if (g[r + 1] != g[r] + 1) {
                    if (g[l] == 1 || g[r] == n || r - l + 1 > w[i]) {
                        len += r - l + 1;
                        if (g[l] != 1 && g[r] != n) cnt++;
                    }
                    l = r + 1;
                }
            }
            cout << cnt * w[i] + (n - len) << ' ';
        }
    }
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}

